home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / lang / c--c0202 / c--info.doc < prev    next >
Encoding:
Text File  |  1994-11-03  |  58.0 KB  |  1,557 lines

  1.  
  2.     C--INFO.DOC >>> INFORMATION ON THE SPHINX C-- PROGRAMMING LANGUAGE
  3.  
  4.     Copyright Peter Cellik (C) 1994.  All rights reserved.
  5.  
  6.     Last Updated:  3 Nov 1994
  7.  
  8. =============================================================================
  9.  
  10. See ALLPROCS.DOC for a complete list of all stack procedures, REG procedures
  11.          and macros in the C-- library.
  12. See STAKPROC.DOC for a more detailed description of all stack procedures.
  13. See REGPROC.DOC for a more detailed description of all REG procedures and
  14.         macros.
  15. See WBHELP.DOC for help on using the C-- Work Bench.
  16. See C--ASM.DOC for help on C-- inline assembly.
  17.  
  18. =============================================================================
  19.  
  20. TABLE OF CONTENTS
  21. ^^^^^^^^^^^^^^^^^
  22.  
  23. 0     INTRODUCTION
  24.    
  25. 0.1   C--, what can it do?
  26. 0.2   C--, what is it like?
  27.  
  28. 1     THE C-- LANGUAGE
  29.    
  30. 1.0   Section Introduction
  31. 1.1   Identifiers
  32.     1.1.1  Identifier Format
  33.     1.1.2  Reserved Identifiers
  34. 1.2   Constants
  35.     1.2.1  Numerical Constants
  36.     1.2.2  Character Constants
  37.     1.2.3  String Constants
  38.     1.2.4  Constant Expressions
  39. 1.3   Data Types
  40.     1.3.1  Types of Variables
  41.     1.3.2  Declaration of Global Variables
  42. 1.4   Expressions
  43.     1.4.1  Types of Expressions
  44.     1.4.2  EAX/AX/AL Expressions
  45.     1.4.3  Non-EAX/AX/AL Expressions
  46.     1.4.4  Conditional Expressions
  47.         1.4.4.1  Simple Conditional Expressions
  48.         1.4.4.2  Complex Conditional Expressions
  49. 1.5   Declaring Procedures, Functions and Macros
  50.     1.5.1  Types of Procedures, Functions and Macros
  51.     1.5.2  Stack Procedures
  52.     1.5.3  REG Procedures
  53.     1.5.4  Dynamic Procedures
  54.     1.5.5  Return Values
  55. 1.6   Using Procedures, Functions and Macros
  56.     1.6.1  Stack Procedures
  57.     1.6.2  REG Procedures
  58.     1.6.3  Macros
  59. 1.7   Selection Statements
  60. 1.8   Looping Statements
  61.     1.8.1  Types of Looping Statements
  62.     1.8.2  'do {} while' Loops
  63.     1.8.3  'loop' Loops
  64. 1.9   Array Indexing
  65.     1.9.1  Relative Addressing
  66.     1.9.2  Absolute Addressing
  67. 1.10  Jump Labels
  68. 1.11  Other Syntax
  69.     1.11.1  Swap Operator
  70.     1.11.2  Neg Operator
  71.     1.11.3  NOT Operator
  72.     1.11.4  Special Conditional Expressions
  73.     1.11.5  Interrupt Procedures
  74. 1.12  Compiler Directives
  75. 1.13  Inline Assembly
  76.  
  77. 2     OUTPUT FILE FORMATS
  78.  
  79. 2.1  COM File Output
  80. 2.2  EXE File Output
  81. 2.3  Object File Output (*.OBJ)
  82.  
  83. 3     COM FILE SYMBIOSIS
  84.  
  85. 3.0   What is it?
  86. 3.1   Hows it done
  87. 3.2   How to do it
  88. 3.3   Uses
  89. 3.4   Abuses
  90.  
  91. 4     LOW LEVEL INFORMATION
  92.  
  93. 4.1   Format of C--'s Stack Frames
  94.    
  95. 5     COMMAND LINE OPTIONS FOR THE C-- COMPILER
  96.  
  97. 6     CURRENT LIMITATIONS OF C--
  98.  
  99. A     APPENDIX
  100.  
  101. A.1   Registers That Must Be Preserved
  102. A.2   Table of C-- Symbols
  103. A.3   C-- Version Notes
  104.  
  105. =============================================================================
  106.  
  107. 0  Introduction
  108. ^^^^^^^^^^^^^^^   
  109.  
  110. 0.1  C--, what can it do?
  111.  
  112. C-- was designed to build small and fast programs.  It is most suitable for 
  113. memory resident programs (TSRs), programs requiring interrupt handling or
  114. programs that have limited resources.
  115.  
  116. C-- supports, among other things, inline assembly and recursion.  Also the
  117. internal C-- library of functions and macros, contains code support for 
  118. files, sound, graphics and access to extended memory by the use of the XMS
  119. standard 2.0.
  120.  
  121. -----------------------------------------------------------------------------
  122.  
  123. 0.2  C--, what is it like?
  124.  
  125. Nothing you have experienced before.  :-)
  126. Seriously, its sort of like C and kinda like assembly.
  127.  
  128. =============================================================================
  129.  
  130. 1  THE C-- LANGUAGE
  131. ^^^^^^^^^^^^^^^^^^^   
  132.  
  133. 1.0  SECTION INTRODUCTION
  134.  
  135. After pondering for quite some time over what the best method to explain C--
  136. to a new user, I came to the conclusion of describing some of its syntax and
  137. usage as a contrast to C.  This does limit the explanation's usefulness to
  138. only C programmers, but since anyone who is anyone knows C, I don't see it a
  139. problem.  :-)
  140.  
  141. -----------------------------------------------------------------------------
  142.  
  143. 1.1  IDENTIFIERS
  144.  
  145. 1.1.1  Identifier Format
  146.  
  147. C-- identifiers must start with either an underscore (_) or an upper or lower
  148. lower case letter.  The then may be followed by any combination of
  149. underscores, upper or lower case letters or numerical digits (0 to 9).  The
  150. total length of an identifier may not exceed 32 characters.
  151.  
  152. Some examples of valid C-- indentifiers are:
  153.  
  154. _DOG
  155. CoW
  156. loony12
  157. HowdYBoys_AND_Girls
  158. WOW___
  159. x
  160.  
  161. Some examples of invalid C-- indentifiers are:
  162.  
  163. 12bogus       /* cannot start an identifier with a numerical digit */
  164. wowisthisalongidentifieryupitsureisnotOK  /* identifier length exceeds 32 */
  165. y_es sir      /* spaces not allowed */
  166. the-end       /* hyphens not allowed */
  167.  
  168.  
  169. 1.1.2  Reserved Identifiers
  170.  
  171. The following is a list of C-- reserved identifiers which can not be used as
  172. general identifiers for they have already been defined or reserved for other
  173. language purposes:
  174.  
  175.     byte    word    char    int     dword   long
  176.     fixed32s        fixed32u
  177.  
  178.     if      loop    return  do      while   else    interrupt
  179.     void    enum    inline  CARRYFLAG       ELSE    EXTRACT
  180.     FALSE   FROM    IF      NOTCARRYFLAG    NOTOVERFLOW
  181.     OVERFLOW        TRUE    ZEROFLAG        NOTZEROFLAG
  182.     far
  183.  
  184.     __CODEPTR__     __DATAPTR__     __POSTPTR__     __COMPILER__
  185.     __DATESTR__     __YEAR__        __MONTH__       __DAY__
  186.     __HOUR__        __MINUTE__      __SECOND__      __WEEKDAY__
  187.     __VER1__        __VER2__
  188.  
  189.     ESBYTE  ESWORD  ESCHAR  ESINT   ESDWORD ESLONG
  190.     ESFIXED32S      ESFIXED32U
  191.     CSBYTE  CSWORD  CSCHAR  CSINT   CSDWORD CSLONG
  192.     CSFIXED32S      CSFIXED32U
  193.     SSBYTE  SSWORD  SSCHAR  SSINT   SSDWORD SSLONG
  194.     SSFIXED32S      SSFIXED32U
  195.     DSBYTE  DSWORD  DSCHAR  DSINT   DSDWORD DSLONG
  196.     DSFIXED32S      DSFIXED32U
  197.     FSBYTE  FSWORD  FSCHAR  FSINT   FSDWORD FSLONG
  198.     FSFIXED32S      FSFIXED32U
  199.     GSBYTE  GSWORD  GSCHAR  GSINT   GSDWORD GSLONG
  200.     GSFIXED32S      GSFIXED32U
  201.  
  202.     AX  CX  DX  BX  SP  BP  SI  DI 
  203.     AL  CL  DL  BL  AH  CH  DH  BH 
  204.     ES  CS  SS  DS  FS  GS  HS  IS 
  205.     EAX ECX EDX EBX ESP EBP ESI EDI
  206.  
  207.     CR0 CR1 CR2 CR3 CR4 CR5 CR6 CR7
  208.     DR0 DR1 DR2 DR3 DR4 DR5 DR6 DR7
  209.     TR0 TR1 TR2 TR3 TR4 TR5 TR6 TR7
  210.  
  211. This list can be obtained from the C-- compiler at anytime by running it
  212. with the /KEYWORDS command line option.
  213.  
  214. -----------------------------------------------------------------------------
  215.  
  216. 1.2  CONSTANTS
  217.  
  218. 1.2.1  Numerical Constants
  219.  
  220. Expressing numerical constants in decimal (base 10) or hexadecimal (base 16) 
  221. are the same as in C.  To express a numerical constant in binary (base 2)
  222. notation, the sequence of 1's and 0's are preceded by 0b, with no spaces in
  223. between.  To express a numerical constant in octal (base 8) notation, the
  224. sequence of octal digits (0 to 7) are preceded by 0o with no spaces.
  225.  
  226. Some examples:
  227.     0b11111111     // same as 255
  228.     0x00F          // same as 15
  229.     0o10           // same as 8
  230.  
  231.  
  232. 1.2.2  Character Constants
  233.  
  234. Single character constants are, like in C, enclosed in single quotes (').
  235. Also as in C, special characters are expressed by a back slash (\) followed
  236. by the key letter or letters.  Special characters supported are:
  237.     '\a'    /* same as in C */
  238.     '\b'    /* beep */
  239.     '\f'    /* form feed */
  240.     '\l'    /* line feed */
  241.     '\n'    /* carrage return */
  242.     '\r'    /* carrage return */
  243.     '\t'    /* tab */
  244.     '\x??'  /* ASCII character formed from the ?? which would be two
  245.            hexadecimal digits for the character value */
  246.     '\???'  /* ASCII character formed from the ??? which would be three
  247.            decimal digits for the character value */
  248. Any other character following a back slash is just accepted.  This allows
  249. the single quote to be included by '\'', for '' is the NULL character.
  250.  
  251. Multiple character constants are also supported by C--.  Some examples of
  252. multiple character constants are:
  253.  
  254.     'ab'
  255.     'the'
  256.     'this is large'
  257.  
  258. There is no limit to the number of characters in a character constant, but
  259. only the last 4 characters are significant.  This is the maximum that can be
  260. stored in a 32 bit variable.  For example, 'this is large' would be
  261. equivalent to 'arge'.
  262.  
  263. C-- treats all character constants as a numeric value of the ASCII value of
  264. the character.  For multiple character constants, the first character is the
  265. most significant, thus the value for 'ab' is 'a'*256+'b'.
  266.  
  267.  
  268. 1.2.3  String Constants
  269.  
  270. String constants, like in C, are inclosed in double quotes (").  Special
  271. characters are expressed within strings the same way as in character 
  272. constants.  All the special characters are the same as in character constants
  273. with the exception of \n which inserts both a carrage return and a line feed.
  274.  
  275. The current maximum length of string constants is 1000 including the 0
  276. terminator, thus a maximum of 999 characters.
  277.  
  278.  
  279. 1.2.4  Constant Expressions
  280.  
  281. A constant expression is single numerical constant or a list of numerical
  282. constants linked together by operators which are evaluated at compile time to
  283. a single constant value.
  284.  
  285. Like all expressions in C--, constant expressions are always evaluated from
  286. left to right, regardless of operations!  This is quite different that most
  287. other languages, and care must be used to remember that 2 + 3 * 2 = 10 and
  288. not 8.
  289.  
  290. All numerical values in C-- are integer values.
  291.  
  292. Some examples of constant expressions are:
  293. 45 & 1 + 3         // equals 4
  294. 14 - 1 / 2         // equals 6 (remember integer values)
  295. 1 * 2 * 3 / 2 + 4  // equals 7
  296.  
  297. -----------------------------------------------------------------------------
  298.  
  299. 1.3  DATA TYPES
  300.  
  301.  
  302. 1.3.1  Types of Variables
  303.  
  304. There eight memory variable types in C--, they are byte, word, dword, char,
  305. int, long, fixed32s and fixed32u.  The following table shows the size and
  306. range of each of the variable types:
  307.  
  308.    NAME   | SIZE  |        VALUE RANGE          |        VALUE RANGE
  309.       |(bytes)|         (decimal)           |           (hex)
  310.  ----------------------------------------------------------------------------
  311.   byte    |   1   |           0 to 255          |        0x00 to 0xFF 
  312.   word    |   2   |           0 to 65535        |      0x0000 to 0xFFFF
  313.   dword   |   4   |           0 to 4294967295   |  0x00000000 to 0xFFFFFFFF
  314.  fixed32u |   4   |           0 to 65535.999985 | 0x0000.0000 to 0xFFFF.FFFF
  315.   char    |   1   |        -128 to 127          |        0x80 to 0x7F
  316.   int     |   2   |      -32768 to 32767        |      0x8000 to 0x7FFF
  317.   long    |   4   | -2147483648 to 2147483647   |  0x80000000 to 0x7FFFFFFF
  318.  fixed32s |   4   |      -32768 to 32767.999985 | 0x8000.0000 to 0x7FFF.FFFF
  319.  
  320. NOTE1: 32 bit (4 byte) integer instructions are used to implement dword,
  321.        long, fixed32s and fixed32u values, therefore support for these data
  322.        types is limited to 80386 and higher CPU's.
  323. NOTE2: fixed32s and fixed32u are not fully implemented, and will be available
  324.        future versions of C--.
  325.  
  326. 1.3.2  Declaration of Global Variables
  327.  
  328. The syntax for declaring variables is as follows:
  329.  
  330. variable-type identifier;
  331.  
  332. Where variable-type is any one of char, byte, int, word, long or dword.
  333. Several identifers may be declared of the same type as follows:
  334.  
  335. variable-type identifier1, identifier2, ... , identifierN;
  336.  
  337. One dimensional arrays may be declared as follows:
  338.  
  339. variable-type identifier[elements];
  340.  
  341. Where elements is a constant expression for the amount of entries of that
  342. variable type to be in the array.
  343.  
  344. Some examples of global declarations:
  345.  
  346. byte i,j;       /* declare i and j to be of type byte */
  347. word see[10]    /* declare see to be an array of 10 word's */
  348. int  h,x[27]    /* declare h to be of type int and declare x to
  349.                    be an array of 27 int's */
  350.  
  351. -----------------------------------------------------------------------------
  352.  
  353. 1.4  EXPRESSIONS
  354.  
  355. 1.4.1  Types of Expressions
  356.  
  357. There are three types of expressions in C--, not counting constant
  358. expressions.  They are EAX/AX/AL expressions, non-EAX/AX/AL expressions and
  359. conditional expressions.  All C-- expressions are evaluated left to right,
  360. regardless of the operations involved.
  361.  
  362.  
  363. 1.4.2  EAX/AX/AL Expressions
  364.  
  365. EAX/AX/AL math is used for expressions which the result will be stored in a
  366. memory variable or the EAX, AX or AL register.  If the expression is going to
  367. be stored in a char or byte variable, AL math will be used.  If the
  368. expression is going to be stored in a int or word variable, AX math will be
  369. used.  If the expression is going to be stored in a long or dword variable,
  370. EAX math will be used.
  371.  
  372. If there are no procedure calls in an EAX/AX/AL expression, only the
  373. values of AX (or EAX or AL), CX  (or ECX or CL) and DX (or EDX or DL) may be
  374. destroyed, all other register values will be preserved during and after the
  375. expression is evaluated.
  376.  
  377.  
  378. 1.4.3  Non-EAX/AX/AL Expressions
  379.  
  380. Non-EAX/AX/AL math is used for expressions which the result will be stored
  381. in a register other than EAX, AX or AL.  With non-EAX/AX/AL only the result
  382. register's value will change, all other register values will be preserved,
  383. the high byte of the byte registers may be destroyed, if a word value is
  384. used with an expression which will be stored in a byte register.  This does
  385. however restrict the operations and operands available with non-EAX/AX/AL
  386. math. No MACRO, REG procedure or STACK procedure calls may be made within a
  387. non-AX/AL/EAX expression.
  388.  
  389.  
  390. 1.4.4  Conditional Expressions
  391.  
  392. Conditional expressions are expressions which are used for generating a 'yes'
  393. or 'no' for 'if' statements and 'do {} while' loops.
  394.  
  395. There are two types of conditional expressions, simple and complex.
  396.  
  397. 1.4.4.1  Simple Conditional Expressions
  398.  
  399. Simple conditional expressions are a single token or expression that will be
  400. taken as a 'yes' if the calculated value is non-zero, or a 'no' if the
  401. calculated value is zero.
  402.  
  403. 1.4.4.2  Complex Conditional Expressions
  404.  
  405. Complex conditional expressions are of the following form:
  406.  
  407.     ( leftside compare_op rightside )
  408.  
  409. Where:
  410.     'leftside' is any AL/AX/EAX or constant expression.  The expression
  411.         type will be determined by the first token (register or
  412.         variable)default is 'word', if an other type is desired, the
  413.         keyword 'byte', 'char', 'int', 'long' or 'dword' can
  414.         preceed the expression to specify its type.
  415.     'compare_op' is any one of '==', '!=', '<>', '<', '>', '<=', or '>='.
  416.     'rightside' is any single register, variable or constant expression.
  417.  
  418. Some examples of valid complex conditional expressions:
  419.  
  420.     ( x+y > z )
  421.     (int CX*DX <= 12*3 )
  422.     (byte first*second+hold == cnumber )
  423.  
  424. Some examples of invalid complex conditional expressions:
  425.  
  426.     ( x+y >= x-y ) // rightside is not a single token or constant expr.
  427.     ( z = y )      // '==' not '=' must be used
  428.  
  429. -----------------------------------------------------------------------------
  430.  
  431. 1.5  DECLARING PROCEDURES, FUNCTIONS AND MACROS
  432.  
  433. 1.5.1  Types of Procedures, Functions and Macros
  434.  
  435. There are two main types of procedures, stack and REG procedures.  Stack
  436. procedures pass parameters on the stack and REG procedures pass the
  437. parameters via registers.  Both stack and REG procedures can act as functions
  438. by returning values, via the return() command.  Only REG procedures declared
  439. as dynamic can be used as macros.
  440.  
  441.  
  442. 1.5.2  Stack Procedures
  443.  
  444. Stack procedures are defined by using an identifer that contains at least one
  445. lower case letter, thus they can be easily distingushed from REG procedures
  446. for REG procedure names may not contain any lower case letters.
  447.  
  448. Parameters for stack procedures, if any, may be of any type (specified by
  449. 'byte', 'char', 'word', 'int', 'dword' or 'long').  Parameters are passed
  450. using a Pascal-like calling convention, that is, the first parameter is
  451. pushed first and the second parameter is pushed second, and so on.  The
  452. Pascal-calling convention does not support variable number of parameters,
  453. so you have to be sure to pass the proper number of parameters to a stack
  454. procedure.
  455.  
  456. The following example stack procedure returns the sum as a 'word' of all it
  457. parameters, which are of different types:
  458.  
  459.     word add_them_all (int a,b,c; byte d,e; word x,y)
  460.     {
  461.     return( a+b+c+d+e+x+y );
  462.     }
  463.  
  464.  
  465. 1.5.3  REG Procedures
  466.  
  467. REG procedures are defined by using an identifer that does not contain any
  468. lower case letters.
  469.  
  470. As mentioned, the parameters (if any) for a REG procedure are passed via
  471. registers.  REG procedures have a maximum of 6 parameters.  The registers
  472. used if the parameters are of type 'int' or 'word', in order, are AX, BX, CX,
  473. DX, DI, and SI.  The first four parameters can also be of the type 'char' or
  474. 'byte', in this case AL, BL, CL and DL are used respectively.  Any of the six
  475. parameters can be of type 'long' or 'dword', in which case EAX, EBX, ECX,
  476. EDX, EDI, or ESI would be used.
  477.  
  478. An example of a REG procedure named 'TOGETHER' that returns a 'word' value
  479. which is the first parameter multiplied to the second parameter, both
  480. parameters are 'word's:
  481.  
  482.     word TOGETHER ()  /* AX = first param, BX = second param */
  483.     {
  484.     return( AX * BX );
  485.     }
  486.  
  487. An example of a REG procedure named 'SHOW_NUM' that does not return any value
  488. but writes the first parameter (which is an 'int') followed by the second
  489. parameter (which is a 'byte') to the screen separated by a ':':
  490.  
  491.     void SHOW_NUM ()  /* AX = first number, BL = second number */
  492.     {
  493.     ? PUSH BX
  494.     WRITEINT(int AX);
  495.     WRITE(':');
  496.     ? POP BX
  497.     WRITEWORD(BL);
  498.     }
  499.  
  500. In order for a REG procedure to be used as a macro, it must be declared as a
  501. dynamic procedure.  Dynamic procedures are described in the following
  502. sub-section.
  503.  
  504.  
  505. 1.5.4  Dynamic Procedures
  506.  
  507. Dynamic procedures are procedures which are defined but only inserted into
  508. the program code if called.  Only REG procedures defined as dynamic
  509. procedures may be used as macros.
  510.  
  511. Dynamic procedures are specified by a preceding ':'.
  512.  
  513. Since dynamic procedures can be relocated anywhere in the code and possibly
  514. in more than one location, several restrictions are nessasary.  These
  515. restrictions are:
  516.  
  517.     - Only macros may be used within the dynamic procedure.  Calls to REG
  518.       or stack procedures are illegal.
  519.  
  520.     - Constant strings cannot be defined within a dynamic procedure.  To
  521.       use a constant string within a dynamic procedure, define the
  522.       contant string as a global variable.
  523.  
  524.     - Only local jump labels may be defined within a dynamic procedure.
  525.       Global jump labels are illegal.
  526.  
  527.     - Jumps to addresses outside the dynamic procedure are illegal.  No
  528.       error message will be given, but the results, as you can imagine,
  529.       are unpredictable.
  530.  
  531.     - For dynamic REG procedures that are going to be used as macros, the
  532.       'return()' command can not be used.  See the end of sub-section
  533.       1.5.5 for more info.
  534.  
  535. An example of a dynamic stack procedure:
  536.  
  537.     : void setvideomode (byte mode)
  538.     {
  539.     AL = mode;
  540.     AH = 0;
  541.     $ INT 0x10
  542.     }
  543.  
  544. An example of a dynamic REG procedure (and could be used as a macro):
  545.  
  546.     : int ABS ()  /* AX = number to get absolute value of */
  547.     {
  548.     IF(int AX < 0 )
  549.         -AX;
  550.     }
  551.  
  552.  
  553. 1.5.5  Return Values
  554.  
  555. Return values from functions are returned via registers, below is a table
  556. showing what register is used for each return type:
  557.  
  558.       return type  |  register returned in
  559.     ----------------------------------------
  560.          byte      |        AL
  561.          word      |        AX
  562.          dword     |        EAX
  563.          char      |        AL
  564.          int       |        AX
  565.          long      |        EAX
  566.  
  567. The easiest way to return a value from a function is to use the 'return()'
  568. command, but the appropriate register can also be assigned the required
  569. return value instead.  For example, the following two functions return the
  570. same value:
  571.  
  572.     byte proc_one ()
  573.     {
  574.     return( 42 );
  575.     }
  576.  
  577.     byte proc_two ()
  578.     {
  579.     AL = 42;
  580.     }
  581.  
  582. Take note, for dynamic REG procedures that you wish to use as macros, the
  583. 'return()' command cannot be used, for the 'return()' also executes a 'RET'
  584. command.  Thus for macros that are functions, the appropriate return value
  585. register must be assigned directly.
  586.  
  587. -----------------------------------------------------------------------------
  588.  
  589. 1.6  USING PROCEDURES, FUNCTIONS AND MACROS
  590.  
  591. 1.6.1  Stack Procedures
  592.  
  593. Stack procedures use the pascal calling style for parameters.  Stack
  594. procedures must therefore be called with the same number of parameters as
  595. declared for the procedure.  Stack procedure names must contain at least
  596. one lower case letter to signify that it is a stack procedure, not a REG
  597. procedure.
  598.  
  599. The programmer must specify what the type is for each parameter.  If the
  600. programmer does not specify a type, 'word' will be assumed.
  601.  
  602.     stack_procedure(x,y);
  603.  
  604. is the same as:
  605.  
  606.     stack_procedure(word x,word y);
  607.  
  608. C-- does not remember what the type is for each parameter of a procedure,
  609. care must be used by the programmer to ensure that the types are the same.
  610. For example, if a procedure has three parameters, and the first parameter is
  611. a 'long' and last two are 'int', the programmer must call it in the following
  612. format:
  613.  
  614.     stack_procedure(long x,int x,int x);
  615.  
  616. If the programmer left out the 'long', only 6 bytes will be pushed onto the
  617. stack, not 8.  Unexpected things would then start to happen, so watch out.
  618.  
  619.  
  620. 1.6.2  REG Procedures
  621.  
  622. For REG procedures, the parameters are passed via registers.  The 16 bit
  623. register used for each position is as follows:
  624.  
  625.     REG_PROCEDURE(AX,BX,CX,DX,DI,SI);
  626.  
  627. If byte or char is used in a position, the 8 bit register that is used for
  628. the position is as follows (note that byte or char values cannot be used in
  629. the DI and SI positions):
  630.  
  631.     REG_PROCEDURE(byte AL,byte BL,byte CL,byte DL);
  632.  
  633. If dword or long is used in a positions, the 32 bit register that will be
  634. used for the position is as follows:
  635.  
  636.     REG_PROCEDURE(long EAX,long EBX,long ECX,long EDX,long EDI,long ESI);
  637.  
  638.  
  639. 1.6.3  Macros
  640.  
  641. Macros are simply REG procedures whose code is inserted rather than called.
  642. An '@' symbol is placed before the REG procedure name to specify the code to
  643. be inserted rather than called.  In order for a REG procedure to be used as
  644. a macro, the REG procedure must be declared as a dynamic procedure or found
  645. in the internal library.
  646.  
  647. All other characteristics of macros are identical to REG procedures.
  648.  
  649. -----------------------------------------------------------------------------
  650.  
  651. 1.7  CONDITIONAL STATEMENTS
  652.  
  653. Selection statements, better known as 'if' statements, are similar to those
  654. in C.  C-- has two selections statements.  'if' and 'IF'.  'if' does a near
  655. jump, and 'IF' does a short jump.  'IF' executes faster, and can save up to
  656. 3 bytes in code size but can only jump over 127 bytes of code.
  657.  
  658. Selection statements, like in C can be followed by either a single command,
  659. or a block of many commands enclosed within '{' and '}'.  C-- selection 
  660. statements are restricted to C-- conditional expressions (as described in
  661. section 1.4 Expressions).
  662.  
  663. If more than 127 bytes of code follow an 'IF' statement, the compiler will
  664. issue the following error message:
  665.  
  666.     IF jump distance too far, use if.
  667.  
  668. This can be simply remeded by changing the offending 'IF' statement to 'if'.
  669.  
  670. 'else' and 'ELSE' statements are used just like the 'else' command in C,
  671. except that 'ELSE' has the same 127 byte jump restriction as 'IF' of 127
  672. bytes.  'else' generates 1 more byte of code than 'ELSE'.  
  673.  
  674. 'IF' and 'else', and 'if' and 'ELSE' may be mixed freely, such as the
  675. following example:
  676.  
  677.     if( x == 2 )
  678.         WRITESTR("Two");
  679.     ELSE{WRITESTR("not two.");
  680.         printmorestuff();
  681.         }
  682.  
  683. If more than 127 bytes of code follow an 'ELSE' statement, the compiler will
  684. issue the following error message:
  685.  
  686.     ELSE jump distance too far, use else.
  687.  
  688. Simply change the 'ELSE' statement to 'else' to correct the error.
  689.  
  690. -----------------------------------------------------------------------------
  691.  
  692. 1.8  LOOPING STATEMENTS
  693.  
  694. 1.8.1  Types of Looping Statements
  695.  
  696. C-- has two types of looping statements.  They are 'do {} while' and 'loop'.
  697.  
  698.  
  699. 1.8.2  'do {} while' Loops
  700.  
  701. 'do {} while' loops repeat a block of code while a certain conditional
  702. statement remains true.  The block of code will be executed at least once.
  703. An example of a 'do {} while' loop that loops five times follows:
  704.  
  705.     count = 0;
  706.     do {
  707.         count++;
  708.         WRITEWORD(count);
  709.         WRITELN();
  710.         } while (count < 5);
  711.  
  712. The conditional expression in the 'do {} while' statement must conform to the
  713. same rules as 'IF' and 'if' statements.
  714.  
  715.  
  716. 1.8.3  'loop' Loops
  717.  
  718. 'loop' loops repeat a block of code while the specified variable or register
  719. is different than zero.  At the end of executing the block of code, the
  720. given variable or register is decremented by one, then tested if equal to
  721. zero.  If the variable is not equal to zero, the block of code will be 
  722. executed again, and the process repeated.  An example of a 'loop' loop using
  723. a variable count as the loop counter:
  724.  
  725.     count = 5;
  726.     loop( count )
  727.         {WRITEWORD(count);
  728.         WRITELN();
  729.         }
  730.  
  731. Use of the register CX for small code block loops will yield the greatest
  732. code size efficiency for a 'loop', for the loop will be implemented by the
  733. use of the machine language 'LOOP' command.
  734.  
  735. If the loop counter is zero before starting the 'loop' command, the loop
  736. will be executed the maximum number of times for the range of the variable.
  737. 256 times for a 8 bit (byte or char) counter, 65536 for a 16 bit (word or
  738. int) counter, and 4294967296 for a 32 bit (dword or long) loop counter.  For
  739. example, the following loop will execute 256 times:
  740.  
  741.     BH = 0;
  742.     loop( BH )
  743.         {
  744.         }
  745.  
  746. If no loop counter is given, the loop will loop forever.  The following
  747. example will write *'s to the screen forever:
  748.  
  749.     loop()
  750.         WRITE('*');
  751.  
  752. The programmer may, if he or she wishes to, use and/or change the value of
  753. the loop counter variable within the loop.  For example the following loop
  754. will only execute 3 times:
  755.  
  756.     CX = 1000;
  757.     loop( CX )
  758.         {
  759.         IF( CX > 3 )
  760.         CX = 3;
  761.         }
  762.  
  763. -----------------------------------------------------------------------------
  764.  
  765. 1.9  ARRAY INDEXING
  766.  
  767. 1.9.1  Relative Addressing
  768.  
  769. Elements in an array of ANY TYPE are indexed in byte units, regardless of the
  770. data type.  Indexes are restricted to the format of 8086 RM field, thus only
  771. the following index formats are available (where index is a 16 bit constant
  772. value or constant expression):
  773.  
  774.     variable[index]
  775.     variable[index+BX+SI]
  776.     variable[index+BX+DI]
  777.     variable[index+BP+SI]
  778.     variable[index+BP+DI]
  779.     variable[index+SI]
  780.     variable[index+DI]
  781.     variable[index+BP]
  782.     variable[index+BX]
  783.  
  784. Some examples:
  785.     To assign 1995 to the third word in an array of words called
  786.     'xlocations':
  787.         xlocations[4] = 1995;
  788.  
  789.     To assign 0 to the second long in an array of longs called
  790.     'addresses':
  791.         addresses[4] = 0;
  792.  
  793.     To use the variable 'count' as an index for assigning TRUE to an
  794.     array called 'fast':
  795.         BX = count;
  796.         fast[BX] = TRUE;
  797.  
  798.  
  799. 1.9.2  Absolute Addressing
  800.  
  801. Absolute addressing is also available.  The same restrictions on the indexes
  802. apply as with relative addressing.  The calculated index will be absolute
  803. from the segment register specified.  Any segment register can be used, DS,
  804. CS, SS and ES.  On a 80386+, FS and GS can also be used.
  805.  
  806. The syntax is exactly the same to relative addressing, except that a segment
  807. and type specifier is used.  The specifiers available are:
  808.  
  809.           // addressing the Data Segment 
  810.     DSBYTE[offset]     // address a byte in the DS segment
  811.     DSWORD[offset]     // address a word in the DS segment
  812.     DSCHAR[offset]     // address a char in the DS segment
  813.     DSINT[offset]      // address a int in the DS segment
  814.     DSDWORD[offset]    // address a dword in the DS segment
  815.     DSLONG[offset]     // address a long in the DS segment
  816.  
  817.           // addressing the Code Segment 
  818.     CSBYTE[offset]     // address a byte in the CS segment
  819.     CSWORD[offset]     // address a word in the CS segment
  820.     CSCHAR[offset]     // address a char in the CS segment
  821.     CSINT[offset]      // address a int in the CS segment
  822.     CSDWORD[offset]    // address a dword in the CS segment
  823.     CSLONG[offset]     // address a long in the CS segment
  824.  
  825.           // addressing the Stack Segment 
  826.     SSBYTE[offset]     // address a byte in the SS segment
  827.     SSWORD[offset]     // address a word in the SS segment
  828.     SSCHAR[offset]     // address a char in the SS segment
  829.     SSINT[offset]      // address a int in the SS segment
  830.     SSDWORD[offset]    // address a dword in the SS segment
  831.     SSLONG[offset]     // address a long in the SS segment
  832.  
  833.           // addressing the Extra Segment 
  834.     ESBYTE[offset]     // address a byte in the ES segment
  835.     ESWORD[offset]     // address a word in the ES segment
  836.     ESCHAR[offset]     // address a char in the ES segment
  837.     ESINT[offset]      // address a int in the ES segment
  838.     ESDWORD[offset]    // address a dword in the ES segment
  839.     ESLONG[offset]     // address a long in the ES segment
  840.  
  841.           // addressing the Extra Segment 2 (80386+)
  842.     FSBYTE[offset]     // address a byte in the FS segment
  843.     FSWORD[offset]     // address a word in the FS segment
  844.     FSCHAR[offset]     // address a char in the FS segment
  845.     FSINT[offset]      // address a int in the FS segment
  846.     FSDWORD[offset]    // address a dword in the FS segment
  847.     FSLONG[offset]     // address a long in the FS segment
  848.  
  849.           // addressing the Extra Segment 3 (80386+)
  850.     GSBYTE[offset]     // address a byte in the GS segment
  851.     GSWORD[offset]     // address a word in the GS segment
  852.     GSCHAR[offset]     // address a char in the GS segment
  853.     GSINT[offset]      // address a int in the GS segment
  854.     GSDWORD[offset]    // address a dword in the GS segment
  855.     GSLONG[offset]     // address a long in the GS segment
  856.  
  857. Some examples:
  858.     To load AL with the byte value at the address 0000:0417 hex:
  859.         ES = 0x0000;
  860.         AL = ESBYTE[0x417];
  861.  
  862.     To move a word value from 2233:4455 hex to A000:0002 hex:
  863.         $PUSH DS
  864.         DS = 0x2233;
  865.         ES = 0xA000;
  866.         ESWORD[0x0002] = DSWORD[0x4455];
  867.         $POP DS
  868.  
  869.     To store the int variable X + 2 at address FFFF:1234 hex:
  870.         ES = 0xFFFF;
  871.         ESINT[0x1234] = X + 2;
  872.  
  873.     To store BX in the stack at offset 42:
  874.         SSWORD[42] = BX;
  875.  
  876. -----------------------------------------------------------------------------
  877.  
  878. 1.10  JUMP LABELS
  879.  
  880. Jump labels are used for labeling code locations for use with an inline
  881. assembly jump command.  There are two types of jump labels, global and local.
  882. Global labels, as the name suggests, are labels which are 'visible' from
  883. anywhere in the program.  Local labels are only 'visible' within their own
  884. procedure block and will be undefined outside the block.
  885.  
  886. Labels are defined by a identifier followed by a colon.  If the identifier
  887. used contains one or more lower case letters, it is a global jump label,
  888. otherwise it is a local jump label.
  889.  
  890. Global jump labels must not be used within dynamic procedures, only local
  891. labels may be used.  This is important to remember, for dynamic procedures
  892. are relocated at compile time, and for the case of a dynamic REG procedures
  893. which can actually be in more than one place in the code, by use of the macro
  894. command, thus would result in a label representing more than one address. 
  895.  
  896. -----------------------------------------------------------------------------
  897.  
  898. 1.11  OTHER SYNTAX
  899.  
  900. 1.11.1  Swap Operator
  901.  
  902. C--, I am proud to say, has an operator that I haven't yet found in any other
  903. language, the swap operator.  The swap operator swaps two values.  The symbol
  904. is '><'.  The variables on either side of the swap operator must be of the
  905. same size,  8 bit and 8 bit, 16 bit and 16 bit, or 32 bit and 32 bit.  Some
  906. examples follow:
  907.  
  908.     AX >< BX;  // store the value of BX in AX and the value of AX in BX
  909.     CH >< BL;  // swap the values of CH and BL
  910.     dog >< cat;  /* swap the values of the variable dog and the variable
  911.             cat */
  912.     counter >< CX;  // swap the values of counter and CX
  913.  
  914. If a swap is between two 8 bit memory variables, AL will be destroyed.  If a
  915. swap is between two 16 bit memory variables, AX will be destroyed.  If a swap
  916. is between 32 bit memory variables, EAX will be destroyed.  In all other
  917. cases, such as a memory variable and a register, all register values will be
  918. preserved.
  919.  
  920.  
  921. 1.11.2  Neg Operator
  922.  
  923. C-- supports a quick syntax of toggling the sign of a variable, the Neg
  924. operator.  By placing a '-' infront of a memory variable or register followed
  925. by a ';', the sign of the memory variable or register will be toggled.  Some
  926. examples follow:
  927.  
  928.     -AX;     // same as 'AX = -AX;' but faster.
  929.     -tree;   // same as 'tree = -tree;' but faster.
  930.     -BH;     // toggle the sign of BH.
  931.  
  932.  
  933. 1.11.3  NOT Operator
  934.  
  935. C-- supports a quick syntax of doing a logical NOT toggling on a variable,
  936. the NOT operator.  By placing a '!' infront of a memory variable or register
  937. followed by a ';', the value of the memory variable or register will be
  938. changed to the logical NOT of its current value.  Some examples follow:
  939.  
  940.     !AX;     // same as 'AX ^= 0xFFFF;' but faster.
  941.     !node;   // change the value of 'node' to its logical NOT.
  942.     !CL;     // same as 'CL ^= 0xFF' but faster.
  943.  
  944.  
  945. 1.11.4  Special Conditional Expressions
  946.  
  947. C-- supports six special conditional expressions:
  948.  
  949.     CARRYFLAG
  950.     NOTCARRYFLAG
  951.     OVERFLOW
  952.     NOTOVERFLOW
  953.     ZEROFLAG
  954.     NOTZEROFLAG
  955.  
  956. These can be used in place of any normal conditional expressions.  If for
  957. example you wish to execute a block of code only if the carry flag is set,
  958. then you would use the following code sequence:
  959.  
  960.     IF( CARRYFLAG )
  961.         {
  962.         // do some stuff here
  963.         }
  964.  
  965. If you wish to continuously execute a block of code until the overflow flag
  966. is set, you would use something like the following section of code:
  967.  
  968.     do {
  969.         // do your thing in here
  970.         } while( NOTOVERFLOW );
  971.  
  972.  
  973. 1.11.5  Interrupt Procedures
  974.  
  975. Interrupt procedures, procedures which are used as handles for interrupts,
  976. are defined in the following manner:
  977.  
  978.     interrupt procedure_name ()
  979.     {
  980.     // put code here
  981.     }
  982.  
  983. Interrupt procedures do not automatically preserve any registers, and no
  984. registers are modified before the interrupt gains control, therefore it is
  985. your responsibility to 'push' and 'pop' registers and load the DS register
  986. with the appropriate value as required.  An example of an interrupt handle
  987. that preserves all registers and loads DS follows:
  988.  
  989.     interrupt safe_handle ()
  990.     {
  991.     $ PUSH DS
  992.     $ PUSH ES
  993.     $ PUSHA   // 80286+ processor required for this machine instruction
  994.     DS = CS;  // load DS with appropriate value for tiny memory model
  995.  
  996.     /* do your thing here */
  997.  
  998.     $ POPA   // 80286+ processor required for this machine instruction
  999.     $ POP ES
  1000.     $ POP DS
  1001.     }
  1002.  
  1003. -----------------------------------------------------------------------------
  1004.  
  1005. 1.12  COMPILER DIRECTIVES
  1006.  
  1007. C-- does not contain a preprocessor.  It does however give the user several
  1008. funtions that are very similar to the functions of the C preprocessor.  
  1009. These are given by compiler directives.  All compiler directives begin with
  1010. a '?'.  Below is a list of supported compiler directives and their functions:
  1011.  
  1012. ? align                       /* insert byte into program code if currently
  1013.                  at an odd address. */
  1014. ? aligner (aligner value)     /* set value of insert byte. */
  1015. ? alignword (TRUE or FALSE)   /* enable or disable even address alignment
  1016.                  of words and ints, default is TRUE. */ 
  1017. ? assumeDSSS (TRUE or FALSE)  /* enable or disable assumption of DS == SS
  1018.                  for local and parameter variable
  1019.                  addressing, default is FALSE. */
  1020. ? beep               /* cause the compiler to beep upon reaching this line */
  1021. ? codesize                    /* optimize for code size not speed. */
  1022. ? ctrl_c (TRUE or FALSE )     /* enable or disable ctrl-C ignoring */
  1023. ? define (identifier) (token) /* define an identifier. */
  1024. ? DOSrequired (number)    /* set the minimum DOS version required:
  1025.                  high byte major number, low byte minor number:
  1026.                  0x0101 for DOS version 1.1
  1027.                  0x0315 for DOS version 3.21
  1028.                  0x0303 for DOS version 3.3
  1029.                  0x0600 for DOS version 6.0
  1030.                  0x0602 for DOS version 6.2
  1031.                  etc. */
  1032. ? include ("filename")        /* include another source file. */
  1033. ? jumptomain (NONE, SHORT, NEAR or FALSE)
  1034.           /* set inital jump type to main(), default is NEAR */
  1035. ? maxerrors (number)    /* number of error to find before compiler aborts,
  1036.                default is 16 */
  1037. ? parsecommandline (TRUE or FALSE) /* include command line parsing code into
  1038.                       program, default is FALSE */
  1039. ? pause                     /* pause compiling until user presses a key. */
  1040. ? print (number or string)  /* displays a string or number to the screen */
  1041. ? printhex (number)      /* displays a number in hexadecimal to the screen */
  1042. ? randombyte             /* insert a random byte into program code */
  1043. ? resize (TRUE or FALSE) /* resize program memory block upon start up to the
  1044.                 minimum amount required, default is TRUE */
  1045. ? resizemessage (string) /* message to display before aborting if the
  1046.                 resizing of the program memory block failed. */
  1047. ? speed                 /* optimize for speed (default) not code size */
  1048. ? stack (number)        /* specifies the size of the stack in bytes for the
  1049.                program */
  1050. ? startaddress (number) /* set initial code start address, default 0x100 */
  1051. ? use8086               /* restrict code generation to 8088/8086 (default) */
  1052. ? use8088               /* restrict code generation to 8088/8086 (default) */
  1053. ? use80186              /* enable 80186 code generation and optimizations */
  1054. ? use80286              /* enable 80286 code generation and optimizations */
  1055. ? use80386              /* enable 80386 code generation and optimizations */
  1056. ? use80486              /* enable 80486 code generation and optimizations */
  1057. ? use80586              /* enable 80586 code generation and optimizations */
  1058.  
  1059. -----------------------------------------------------------------------------
  1060.  
  1061. 1.13  INLINE ASSEMBLY
  1062.  
  1063. C-- inline assembly supports all of the 8088/8086 assembly codes, plus most
  1064. of the 80286 and 80386 enhanced instructions.  All codes must start with the
  1065. $ inline assembly specifier.  See the file 'C--ASM.DOC' for a complete list
  1066. of all assembly op codes supported by C--.
  1067.  
  1068.  
  1069. =============================================================================
  1070.  
  1071. 3  OUTPUT FILE FORMATS
  1072. ^^^^^^^^^^^^^^^^^^^^^^
  1073.  
  1074.  
  1075. 2.1  COM File Output
  1076.  
  1077. COM files were initially the only output format of C--.  COM files are still
  1078. the only output format of runable programs of C--, but OBJ output is now also
  1079. available to allow interfacing of C-- with other languages.
  1080.  
  1081.  
  1082. 2.2  EXE File Output
  1083.  
  1084. C-- does not currently output EXE run files.  It might in the future.  It may
  1085. also support EXE files in the future via outputting an OBJ which you can then
  1086. link using a linker not included with the C-- package.  Link use to come free
  1087. with old versions of DOS (memories...).
  1088.  
  1089.  
  1090. 2.3  Object File Output (*.OBJ)
  1091.  
  1092. Starting with version 0.195, C-- is now able to successfully output OBJ
  1093. object files which are Microsoft Compatable.  At the current time C-- can
  1094. only output OBJ files, it can not link them (that is, it can not read any
  1095. input from OBJ files).
  1096.  
  1097. C-- uses the pascal style of parameter passing for STACK procedures and 
  1098. STACK functions.  Therefore, any procedures or functions exported via an OBJ
  1099. object file must be accessed using a pascal calling style.  This is fine if
  1100. you are linking with pascal, but for C you must declare the procedure or
  1101. function as a 'pascal' (or '__pascal') procedure or function in order for the
  1102. C compiler to properly set up the parameters when calling your C-- procedure
  1103. or function.
  1104.  
  1105. You guys that program in assembly and wish to link with C-- should be bright
  1106. enough to have no difficultly calling C-- procedures and function linked in
  1107. via an OBJ object file.
  1108.  
  1109. When creating procedures and function for OBJ output, be sure to preserve the
  1110. registers required for the target language.  References on the specific
  1111. language or compiler should supply you with this information.  According to
  1112. Microsoft documentation for C, you should preserve the values of BP, SP, SI,
  1113. DI, SS and DS.  According to Borland documentation for Turbo Pascal, you
  1114. should preserve the values of BP, SP, SS, and DS.  Expand your volcabulary
  1115. and read up on this stuff in your compiler manuals.
  1116.  
  1117. Global variable references currently don't work so hot in OBJ output files.
  1118. The global data will be included in the OBJ file, and is available, but the
  1119. global references used in you C-- procedures may generate an incorrect
  1120. address.  I know why this happens, I sort of know the solution, I, I..., I
  1121. will soon fix this problem.  For the time being, exporting of C-- procedures
  1122. will work fine, so long as you do not reference any global data.
  1123.  
  1124. The 'far' keyword has been added to allow you to declare procedure that do
  1125. a far return (20 bit) as oposed to the default near return (16 bit).
  1126.  
  1127.  
  1128. =============================================================================
  1129.  
  1130. 3  COM FILE SYMBIOSIS
  1131. ^^^^^^^^^^^^^^^^^^^^^
  1132.  
  1133. 3.0  WHAT IS IT?
  1134.  
  1135. The C-- compiler has the option to append the program it is compiling to the
  1136. end of an already created COM file.  This I call "COM File Symbiosis".  When
  1137. the program is loaded, execution will start in the appended C-- code, and
  1138. when execution passes the end of the main() procedure block, execution of the
  1139. original program will begin.  If a procedure like EXIT() or ABORT() is
  1140. called within the C-- program, the program will quit, and the original code
  1141. from the COM file will not be executed.  This allows the program being
  1142. appended on to the COM file to determine whether control will be passed onto
  1143. the original code.
  1144.  
  1145.  
  1146. 3.1  HOWS IT DONE
  1147.  
  1148. I will tell you later, its not really that complicated.
  1149.  
  1150.  
  1151. 3.2  HOW TO DO IT
  1152.  
  1153. To do it, you need to use the /SYM command line option followed by the full
  1154. name of the COM file to append to.  The original COM file will not be
  1155. changed, only copied into the beginning of the outputted run COM file.  For
  1156. example, to compile the program HELLO.C-- on to the end of a copy of
  1157. C:\COMMAND.COM use the following command:
  1158.  
  1159.     C-- /SYM C:\COMMAND.COM HELLO.C-- 
  1160.  
  1161. An output file HELLO.COM will be created.
  1162.  
  1163.  
  1164. 3.3  USES
  1165.  
  1166. You can probably think of lots of ways of using this function, such as:
  1167.  
  1168.     - Adding password protection to certain special COM files.
  1169.     - Reducing the memory available to the COM file at start up.
  1170.     - Initializing a video mode for the COM file.
  1171.  
  1172.  
  1173. 3.4  ABUSES
  1174.  
  1175. Anyone with a mischievous mind (most people do) can think of some not so nice
  1176. ways of using this function.  The most obvious of which would be the creation
  1177. of trojan horses.  I WOULD LIKE TO POINT OUT THAT THIS IS NOT A CONSTRUCTIVE
  1178. USE OF C-- AND ANY DESTRUCTIVE USE OF COM FILE SYMBIOSIS IS PROHIBITED.  In
  1179. other words, don't be a jerk.
  1180.  
  1181.  
  1182. =============================================================================
  1183.  
  1184. 4  LOW LEVEL INFORMATION
  1185. ^^^^^^^^^^^^^^^^^^^^^^^^
  1186.  
  1187. 4.1   Format of C--'s Stack Frames
  1188.  
  1189. C-- STACK FRAME for near (default) stack procedures:
  1190.     ADDRESS
  1191.       ...
  1192.     BP+FFFE   second from last byte of local variables
  1193.     BP+FFFF   last byte of local variables
  1194.     BP+0000   Saved BP
  1195.     BP+0002   RET address
  1196.     BP+0004   last word of parameter variables
  1197.     BP+0006   second from last word of parameter variables
  1198.       ...
  1199.  
  1200. C-- STACK FRAME for far stack procedures:
  1201.     ADDRESS
  1202.       ...
  1203.     BP+FFFE   second from last byte of local variables
  1204.     BP+FFFF   last byte of local variables
  1205.     BP+0000   Saved BP
  1206.     BP+0002   RETF address (high)
  1207.     BP+0004   RETF address (low)
  1208.     BP+0006   last word of parameter variables
  1209.     BP+0008   second from last word of parameter variables
  1210.       ...
  1211.  
  1212.    
  1213. C-- STACK FRAME for interrupt procedures:
  1214.     ADDRESS
  1215.       ...
  1216.     BP+FFFE   second from last byte of local variables
  1217.     BP+FFFF   last byte of local variables
  1218.     BP+0000   Saved BP
  1219.     BP+0002   Saved Flags
  1220.     BP+0004   RETF address (high)
  1221.     BP+0006   RETF address (low)
  1222.     BP+0008   last word of parameter variables
  1223.     BP+000A   second from last word of parameter variables
  1224.       ...
  1225.  
  1226.  
  1227. =============================================================================
  1228.  
  1229. 5  COMMAND LINE OPTIONS FOR THE C-- COMPILER
  1230. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1231.  
  1232. The command line calling format of the C-- compiler is:
  1233.  
  1234. C-- [options] <SOURCE FILE NAME without extension>
  1235.  
  1236. Where options are (short forms are enclosed in '()'):
  1237.  
  1238. /8086           << restrict code generation to simple 8086, default (/0)
  1239. /8088           << restrict code generation to simple 8086, default (/0)
  1240. /80286          << enable 80286 code optimizations (/2)
  1241. /80386          << enable 80386 code optimizations (/3)
  1242. /80486          << enable 80486 code optimizations (/4)
  1243. /80586          << enable 80586 (P5) code optimizations (/5)
  1244. /80686          << enable 80686 (P6) code optimizations (/6)
  1245. /-ALIGN         << disable even word address alignment (/-A)
  1246. /+ALIGN         << enable even word address alignment, default (/+A)
  1247. /-ASSUMEDSSS    << disable assumption of DS=SS optimization, default (/-D)
  1248. /+ASSUMEDSSS    << enable assumption of DS=SS optimization (/+D)
  1249. /-CTRLC         << do not insert CTRL<C> ignoring code, default (/-C)
  1250. /+CTRLC         << insert CTRL<C> ignoring code (/+C)
  1251. /EXE            << produce EXE run file, almost available (/E)
  1252. /HELP           << get a little help, not much (/?)
  1253. /KEYWORDS       << display list of C-- reserved words
  1254. /MACRO <name>   << extract macro from internal library
  1255. /-MAP           << do not generate map file, default (/-M)
  1256. /+MAP           << generate map file. (/+M)
  1257. /ME             << display my name and my address
  1258. /-MAIN          << disable initial jump to main() (/J0)
  1259. /+MAIN          << set initial jump to main() to be near, default (/J2)
  1260. /OBJ            << produce OBJ output file
  1261. /-RESIZE        << do not insert resize program memory block code (/-R)
  1262. /+RESIZE        << insert resize program memory block code, default (/+R)
  1263. /-PARSE         << do not insert parse command line code, default (/-P)
  1264. /+PARSE         << insert parse command line code (/+P)
  1265. /PROC <name>    << extract procedure from internal library
  1266. /QUOTE          << display quote of the program (QOTP)
  1267. /REGPROC <name> << extract REG-procedure from internal library
  1268. /+RESIZE        << insert resize memory block code, default (/+R)
  1269. /S=#####        << set stack size to ##### decimal value
  1270. /SIZE           << optimize for code size (/OC)
  1271. /SHORTMAIN      << initial jump to main() short (/J1)
  1272. /SPEED          << optimize for speed (default) (/OS)
  1273. /STACK          << activate compile time compiler stack check
  1274. /SYM <file>     << COM file symbiosis
  1275. /X              << disable SPHINX C-- header in output file
  1276.  
  1277. Many of these command line options can be overridden by compiler directives
  1278. in the source file.
  1279.  
  1280.  
  1281. =============================================================================
  1282.  
  1283. 6  CURRENT LIMITATIONS OF C--
  1284. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1285.  
  1286. - You may have found, in the documentation, parts that seem rather thin.
  1287.   Every week or so, the documentation for C-- becomes a little more robust,
  1288.   and hopefully more helpful.  Be on the look out for new versions of C--.
  1289.  
  1290. - 32 bit data types require 386 or above processor.  I am not too bothered
  1291.   with this limitation.  Most machines these days are 386+ and using the
  1292.   386 instructions to do 32 bit operations is so much faster.  Hey if you've
  1293.   got it, use it!
  1294.  
  1295. - No floating point variables.  If the demand for floating point types of
  1296.   variables is high, they may be included in future versions.  They were
  1297.   omitted because of the large amount of support code required to handle
  1298.   the mathematical operations.  One possibility maybe that floating point
  1299.   support will be restricted to 8087+, and that software emulation will
  1300.   not be done.
  1301.  
  1302. - I have just started the implementation of a 32 bit fixed point variables,
  1303.   giving 16 bits integer and 16 bits fractional parts.  Fixed point is fast,
  1304.   and hey, who doesn't like speed.  Hopefully I will get them done soon.
  1305.  
  1306. - Limited libraries.  Dynamic procedures were introduced with version 0.170.
  1307.   This now allows all procedures to be defined within include files (*.h),
  1308.   thus making them available for the programmer to improve and change to his
  1309.   needs.  Currently, a number of procedures are still containned within the
  1310.   interal library, in the future, most of these will moved to include files
  1311.   and converted back to C-- code.
  1312.   You may also notice that in VGA.H--, some procedures have been extracted
  1313.   from the interal library but not yet converted back from binary data to
  1314.   C-- code.  I'll get around to it, but they should still be useful as they
  1315.   are.
  1316.   There is now support for the Gravis Ultra Sound by use of the YEA_GUS.EXE
  1317.   sound driver.  If anyone has a better way of programming the card, give me
  1318.   a yell.  Support for other sound cards would also be nice.
  1319.   Send me any code or ideas for procedures that you wish to be added, and I
  1320.   will see what I can do.  If you do send code, it will definitely make it
  1321.   easier on me, C++, C, C-- or ASM doesn't matter.  Also, if you find any
  1322.   errors or possible optimizations to any of the existing procedures, send it
  1323.   to me.
  1324.  
  1325. - Code, Stack and declared Data limited to 64K total.  Well that's the
  1326.   problem with COM files.  With the use of GETMEM() and FREEMEM(), large data
  1327.   buffers can be allocated for use, which usually satisfies most program
  1328.   requirements.  I might in the future I may complete the EXE file output
  1329.   option.  If I do add EXE output, it would be a small memory model (64K
  1330.   Code, 64K Data and Stack), to keep with the design philosophy of C--, which
  1331.   is to make small and fast programs.
  1332.  
  1333. - The tilda '~' is currently not used for anything in C--.  Can you think of
  1334.   and essential use for it in C--?  If so, tell me.  I've had some strange
  1335.   ones...
  1336.  
  1337. - You tell me.  What have you found limiting about C--, and what do you feel
  1338.   should be done about it.  C-- is new, and must grow.  I need your input.
  1339.   Be bold, express you view.  I won't take offense, I just might not agree.
  1340.  
  1341. ============================================================================
  1342.  
  1343. A  APPENDIX
  1344. ^^^^^^^^^^^
  1345.  
  1346. A.1  REGISTERS THAT MUST BE PRESERVED
  1347.  
  1348. Registers that should be preserved are BP, DI, SI, DS, SS, SP, CS and IP.
  1349.  
  1350. BP is used for pointing to local and parameter variables on the stack, and
  1351. thus must be preserved.
  1352.  
  1353. DI and SI need not be preserved if the programmer is aware of the
  1354. consequences.  DI and SI are often used for indexing arrays such as the
  1355. statement:  dog = firehydrant(1,red) + legs[DI];.  If DI was not preserved in
  1356. the procedure firehydrant, then the value moved into dog would probably not
  1357. be the desired value, for the index for legs would have been changed.  As a
  1358. matter of consistency, all procedures should supply addequate comments if DI
  1359. and/or SI are not preserved.
  1360.  
  1361. DS points to the data segment and all global variable operations requires its
  1362. value.
  1363.  
  1364. SS holds the segment of the stack and must be preserved.  SP points to the
  1365. current position on the stack and must be preserved.
  1366.  
  1367. CS holds the segment of the program code.  All instructions are fetched
  1368. using CS and IP, therefore their values must be preserved.  IP, by the way is
  1369. the Instruction Pointer, and CS and IP can not be directly modified on the
  1370. 8086, 8088, 80286, 80386, 80486, 80586 and probably not the 80686 either.
  1371.  
  1372. FS and GS are the new extra segment registers introduced with the 80386.  Do
  1373. what you want with these.
  1374.  
  1375. -----------------------------------------------------------------------------
  1376.  
  1377. A.2  TABLE OF C-- SYMBOLS
  1378.  
  1379. SYMBOL | FUNCTION               | EXAMPLE
  1380. ------------------------------------------------------------------------
  1381.   /*   | start comment block    | /* comment */
  1382.   */   | end comment block      | /* comment */
  1383.        |                        |
  1384.   //   | comment to end of line | // comment
  1385.        |                        |
  1386.    =   | assignment             | AX = 12;
  1387.    +   | addition               | AX = BX + 12;
  1388.    -   | subtraction            | house = dog - church;
  1389.    *   | multiplication         | x = y * z;
  1390.    /   | division               | x1 = dog / legs;
  1391.    &   | bitwise AND            | polution = stupid & pointless;
  1392.    |   | bitwise inclusive OR   | yes = i | mabe;
  1393.    ^   | bitwise exclusive OR   | snap = got ^ power;
  1394.   <<   | bit shift left         | x = y << z;
  1395.   >>   | bit shift right        | x = y >> z;
  1396.        |                        |
  1397.   +=   | addition               | fox += 12;   // fox = fox +12; 
  1398.   -=   | subtraction            | cow -= BX;   // cow = cow - BX; 
  1399.   &=   | bitwise AND            | p &= q;      // p = p & q; 
  1400.   |=   | bitwise inclusive OR   | p |= z;      // p = p | z; 
  1401.   ^=   | bitwise exclusive OR   | u ^= s;      // u = u ^ s; 
  1402.   <<=  | bit shift left         | x <<= z;     // x = x << z 
  1403.   >>=  | bit shift right        | x >>= z;     // x = x >> z
  1404.        |                        |
  1405.   ><   | swap                   | x >< y;  /* exchange values of x and y */
  1406.        |                        |
  1407.   ==   | equal to               | IF(AX == 12)
  1408.    >   | greater than           | IF(junk > BOGUS)
  1409.    <   | less than              | if( x < y )
  1410.   >=   | greater or equal to    | if(AX >= 12)
  1411.   <=   | less than or equal to  | IF(BL >= CH)
  1412.   !=   | not equal to           | IF(girl != boy)
  1413.   <>   | different than         | IF(cat <> dog)  /* same function as != */
  1414.        |                        |
  1415.    @   | insert code            | @ COLDBOOT();  /* insert COLDBOOT code */
  1416.    :   | dynamic procedure      | : functionname () // declare functionname
  1417.    $   | assembly operation     | $ PUSH AX      /* push AX onto stack */
  1418.    #   | offset address of      | loc = #cow;    /* loc = address of cow */
  1419.        |                        |
  1420.    ~   |                        | This symbol is currently unused.
  1421.  
  1422. -----------------------------------------------------------------------------
  1423.  
  1424. A.3   C-- VERSION NOTES
  1425.  
  1426.   Version #         Comments
  1427.   ^^^^^^^^^         ^^^^^^^^
  1428.  up to 0.187    - Lots of versions, and lots of stuff changed.
  1429.  
  1430.     0.187a      - VGAX.H-- modified.
  1431.         - VGA.H-- supplemented.
  1432.         - VGAFILL.H-- added.
  1433.  
  1434.     0.188       - Fixed two lame compare statement bugs.
  1435.         - Spiffed up docs a bit more.
  1436.         - KEYCODES.H-- modified and supplemented.
  1437.         - VIDEO.H-- modified and supplemented.
  1438.         - WRITEHEX(word_value) added to WRITE.H--.
  1439.         - STARS.C-- added.
  1440.         - DPMI.H-- and DPMI.C-- added.
  1441.         - ZEROFLAG and NOTZEROFLAG conditional expressions added.
  1442.  
  1443.     0.189       - Fixed local_var = seg_reg bug.
  1444.         - Everyone should upgrade at least to this version!
  1445.  
  1446.     0.189a      - Docs spiffed.
  1447.         - STARS.C-- modified.
  1448.         - DOS.H-- supplemented.
  1449.         - COMPLETE.C-- added.
  1450.         - DPMI.H-- and DPMI.C-- modified.
  1451.         - DOSWRITESTR() added to DOS.H--.
  1452.  
  1453.     0.190       - DOSWRITESTRING() deleted from internal library.
  1454.         - DOS.H-- supplemented.
  1455.         - DATETIME.C-- added.
  1456.         - Docs spiffed.
  1457.         - Colour Scheme 3 added for all you boring people who didn't
  1458.           like Colour Scheme 1.
  1459.         - VIDEO.H-- supplemented.
  1460.  
  1461.     0.190a      - FIXPATH.C-- ver 1.1 added (created by Jean-Marc
  1462.           Lasgouttes).
  1463.         - Colour Scheme 3 in Work Bench modified just slightly.
  1464.         - Num Pad bug in Work Bench fixed (now version Beta 0.120).
  1465.         - Search bug found in Work Bench but not yet fixed.
  1466.         - Bug found and fixed in TINYDRAW.C-- file selection.
  1467.         - VCPI.H-- and VCPI.C-- added.
  1468.         - ENCRYPT.C-- added.
  1469.         - BOUNCE.C-- modified.
  1470.  
  1471.     0.191       - Functions returning 32 bit values bug found and fixed.
  1472.         - 'fixed32u' and 'fixed32s' now reserved and are keywords,
  1473.           they will be used to define 32bit fixed point (16bit.16bit)
  1474.           variables in the future.
  1475.         - Docs spiffed up a little.
  1476.         - Multiple characters in character constants added.  For
  1477.           example: 'ab'.
  1478.  
  1479.     0.192       - All previous VESA support in VIDEO.H-- removed.
  1480.         - A little more work done on 32bit fixed point stuff.
  1481.         - VESA.H-- and VESA.C-- added.
  1482.         - Offending line in POW4.C-- removed.
  1483.  
  1484.     0.192a      - WAIT() added to SYSTEM.H--.
  1485.         - SOUND BLASTER SUPPORT ADDED!!!  Thanks to Michael B. Martin
  1486.           for all the code.  The following files have been added:
  1487.           SB.H--, SBDMA.H--, SBDETECT.C--, SBGETVOL.C--,
  1488.           SBSETVOL.C--, SB_DMA.C-- and SB_DMA_.C--.
  1489.         - All procedure list is now categorical.
  1490.  
  1491.     0.192b      - FIXPATH.C-- ver 1.1 replaced with ver 1.2.
  1492.         - TSR.H-- added.
  1493.         - KEEP() moved from DOS.H-- to TSR.H--.
  1494.         - PCX.H-- and PCX.C-- added.
  1495.  
  1496.     0.192c      - Procedures added to VGAX.H--.
  1497.  
  1498.     0.192d      - Example files now sorted into multiple directories.
  1499.         - VGAXFNT5.H-- and XFONT5.C-- added.
  1500.  
  1501.     0.193       - Fixed a lame long and dword bug (classic cut and paste
  1502.                   bug).
  1503.  
  1504.     0.194       - Started work on OBJ file output.
  1505.                 - Logitech Cyberman support added (cool toy).
  1506.  
  1507.     0.195       - Tuned OBJ file output.
  1508.         - Modified C-- Work Bench to include OBJ and EXE compiler
  1509.                   output file option (even though EXE is not yet supported
  1510.                   by C--).
  1511.  
  1512.     0.196       - Gained greater mastery of OBJ file format.  Thanks to
  1513.           everyone who sent me info on OBJ and EXE file formats.
  1514.                   Every piece of information helped, you can never have too
  1515.                   many references!.  More work may still have to be done.
  1516.  
  1517.     0.197       - far keyword added.
  1518.         - added CLOCK.C-- written by Gerardo Maiorano.
  1519.  
  1520.     0.198       - OBJ output tested and tuned with Turbo Pascal and Microsoft
  1521.                   C.  OBJ's now work fine, but still do not support global
  1522.                   data.  Will work on this soon.
  1523.         - Docs spiffed.
  1524.  
  1525.     0.198a      - Cool FIRE.C-- added.
  1526.         - OBJ options added to Work Bench (now version 0.123).
  1527.  
  1528.     0.198b      - Same as 0.198a, but a new name was needed to fix upload
  1529.                   error to wuarchive.
  1530.     
  1531.     0.198c      - Work Bench now remembers its video mode (now version
  1532.           0.124).
  1533.  
  1534.     0.199       - The following 80486 additions to inline assembly added:
  1535.           BSWAP, CMPXCHG, INVD, INVLPG, WBINVD and XADD.
  1536.         - File search criteria in Work Bench changed from *.C-- to
  1537.           *.?-- (now version 0.125).
  1538.         - Inline ASM help menu option added to Work Bench (now
  1539.           version 0.126).
  1540.  
  1541.     0.200       - STRCAT() and strcat() bugs found by Johan in STRING.H--
  1542.                   are fixed.
  1543.         - If the first value in a stack or register parameter
  1544.           expression is a dword variable, long variable, 32 bit reg
  1545.           or fixed32 variable, the parameter expression will be
  1546.           assumed to be of that type so long as no override was
  1547.           given.  All other expressions will be assumed to be word
  1548.           type.
  1549.  
  1550.     0.201       - $REP alias for $REPZ added.
  1551.  
  1552.     0.202       - long and dword >< bug fixed.
  1553.         - Compiler recompiled WITHOUT 286 code option.  :-)
  1554.  
  1555. =============================================================================
  1556.  
  1557. /* end of C--INFO.DOC */